<?php

namespace Lib;

class Model {

	public function __get($sClassName) {
		global $o;
		if (! defined ( 'MODEL' )) {
			$sModelPath = $o->Config->get ( 'model.path' );
			if (! $sModelPath) {
				$sModelPath = ROOT . '/model';
			} else {
				$sModelPath = ROOT . '/' . $sModelPath;
			}
			define ( 'MODEL', $sModelPath );
		}
		$sFile = MODEL . '/' . $sClassName . '.class.php';
		try {
			if (is_file ( $sFile )) {
				require_once $sFile;
				$sClass = '\Model\\' . $sClassName;
				if (class_exists ( $sClass )) {
					$oObj = new $sClass ();
					$this->__set ( $sClassName, $oObj );
					return $oObj;
				} else {
					throw new ExceptionExt ( 'class no exist' );
				}
			} else {
				throw new ExceptionExt ( 'class file no exist' );
			}
		} catch ( ExceptionExt $e ) {
			$e->showError ();
		}
	}

	public function __set($sName, $sValue) {
		$this->$sName = $sValue;
	}
}
